#!/usr/bin/env python
# -*- coding:utf-8 -*-
# __author__ = "tingfeng"


import time
from base.base_driver import BaseDriver
from util.read_ini import Read_Ini
from util.server import Server
class GetByLocal:
    def __init__(self,i):
        self.base_driver = BaseDriver()
        self.driver = self.base_driver.android_driver(i)

    def get_element(self,key,section=None):
        # 去localelement拿并区分
        read_ini = Read_Ini()
        local =read_ini.get_value(key,section)
        if local != None: #不等于空才执行下面的步骤
            by = local.split('>')[0]
            local_by = local.split('>')[1]
            #print(local_by)
            if by == 'classname':
                return self.driver.find_elements_by_class_name(local_by)
            elif by == 'xpath':
                return self.driver.find_element_by_xpath(local_by)
            elif by == 'name':
                return self.driver.find_element_by_name(local_by)
            elif by == 'id':
                return self.driver.find_element_by_id(local_by)
        else:
            return None

    # def get_elementB(self,key,section=None):
    #     # 去localelement拿并区分
    #     read_ini = Read_Ini()
    #     local =read_ini.get_value(key,section)
    #     if local != None: #不等于空才执行下面的步骤
    #         by = local.split('>')[0]
    #         local_by = local.split('>')[1]
    #         #print(local_by)
    #         if by == 'classname':
    #             return self.driverB.find_elements_by_class_name(local_by)
    #         elif by == 'xpath':
    #             return self.driverB.find_element_by_xpath(local_by)
    #     else:
    #         return None

if __name__ == '__main__':
    server = Server()
    server.main()
    get_by_local = GetByLocal(0)
    get_by_local.driver.press_keycode(4)
    # time.sleep(5)
    # get_by_local.get_elementC('washcar').click()
    # time.sleep(1)
    # get_by_local.driverC.press_keycode(4)
    # time.sleep(1)
    # get_by_local.get_elementC('refuel').click()
    # get_by_local.driverC.quit()
    # time.sleep(2)
    # get_by_local.driverB.press_keycode(4)
    # time.sleep(1)
    # get_by_local.driverB.press_keycode(4)

